package droid.frame.utils.android;

import android.app.Activity;
import android.provider.Settings;
import android.util.Log;
import android.view.WindowManager;

/**
 * 调节Activity/屏幕亮度的工具类
 * 
 * @author coffee<br>
 *         2014年5月14日下午4:08:55
 */
public class BrightnessUtils {

	/** 可调节的最小亮度值 */
	// private final int MIN_BRIGHTNESS = 30;
	/** 可调节的最大亮度值 */
	private final int MAX_BRIGHTNESS = 255;

	/**
	 * 设置当前Activity的亮度
	 * 
	 * @param progress
	 *            0-255之间
	 */
	public void setActivityBrightness(Activity context, int progress) {
		WindowManager.LayoutParams lp = context.getWindow().getAttributes();
		lp.screenBrightness = progress / (float) MAX_BRIGHTNESS;
		context.getWindow().setAttributes(lp);
	}

	/**
	 * 获得当前系统的亮度值： 0~255
	 */
	public int getSysScreenBrightness(Activity context) {
		int screenBrightness = MAX_BRIGHTNESS;
		try {
			screenBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
		} catch (Exception e) {
			Log.e("BookBrightnessPopWin", "获得当前系统的亮度值失败：", e);
		}
		return screenBrightness;
	}

	public int getMaxBrightness() {
		return MAX_BRIGHTNESS;
	}
}
